package com.lzy.cloud.goods.facade;

import com.lzy.cloud.goods.dtos.CarConfigDto;
import com.lzy.cloud.goods.dtos.ConfigDto;
import com.lzy.cloud.goods.entity.CarConfig;
import com.lzy.cloud.goods.entity.Config;
import com.lzy.cloud.goods.service.CarConfigService;
import com.lzy.cloud.goods.service.ConfigService;
import com.lzy.framework.core.ensure.Ensure;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by WIN7 on 2018/6/11.
 */
@Component
public class ConfigFacade {

    @Autowired
    ConfigService configService;

    @Autowired
    CarConfigService carConfigService;

    public Boolean del(String ids){
        //判断该车内配置是否被占用
        String[] idStrList = ids.split(",");
        for (String id : idStrList) {
            CarConfigDto carConfigDto = new CarConfigDto();
            carConfigDto.setConfigId(Long.valueOf(id));
            List list = carConfigService.selectList(carConfigDto);
            Ensure.that(list.size()).isNotGt(0, "00060006");
            configService.delById(Long.valueOf(id));
        }
        return true;
    }

    public Boolean updateStatus(Integer status, String ids) {
        switch (status){
            case 0:{
                String[] idStrList = ids.split(",");
                for (String id : idStrList) {
                    ConfigDto config = new ConfigDto();
                    config.setId(Long.valueOf(id));
                    config.setStatus(0);
                    configService.update(config);
                }
            }
            case 1:{
                String[] idStrList = ids.split(",");
                for (String id : idStrList) {
                    ConfigDto config = new ConfigDto();
                    config.setId(Long.valueOf(id));
                    config.setStatus(1);
                    configService.update(config);
                }
            }
        }
        return true;
    }
}
